﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LevelEditor.Document;
using LevelEditor.Forms;

namespace LevelEditor.View
{
    class DoUndoMoveLayerDown : DoUndoNothing
    {
        #region Fields

        int DoIndex;
        int UndoIndex;

        Layer Layer;

        #endregion

        #region Constructors

        public DoUndoMoveLayerDown(MainForm form, int index):base(form)
        {
            DoIndex = index - 1;
            UndoIndex = index;

            Layer = form.Level.Layers[UndoIndex];
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            MainForm.Level.Layers.RemoveAt(UndoIndex);
            MainForm.Level.Layers.Insert(DoIndex, Layer);
            MainForm.CurrentLayer = DoIndex;
            MainForm.RefreshControlData();
            return base.Do();
        }

        public override void Undo()
        {
            MainForm.Level.Layers.RemoveAt(DoIndex);
            MainForm.Level.Layers.Insert(UndoIndex, Layer);
            MainForm.CurrentLayer = UndoIndex;
            MainForm.RefreshControlData();
        }

        public override string ToString()
        {
            return "Move layer " + UndoIndex.ToString() + " up";
        }

        #endregion
    }
}
